package com.javakc.platform.modules.circle.topic.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javakc.platform.modules.circle.topic.vo.QueryEntity;
import com.javakc.platform.modules.system.logger.component.annotation.LoggerOperation;
import com.javakc.platform.modules.system.logger.component.enumerate.LoggerEnumerate;
import com.javakc.platform.modules.circle.topic.entity.CircleTopic;
import com.javakc.platform.modules.circle.topic.service.CircleTopicService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

/**
* @author zhouhonggang
* @version 1.0.0
* @project springboot-development-platform
* @datetime 2022-04-16
* @description: [圈子话题·接口]
*/
@RestController
@RequestMapping("circle/topic")
public class CircleTopicController {

    @Resource
    private CircleTopicService circleTopicService;

    /**
     * 话题接口
     * 1、首页话题 重点推荐
     * 2、圈子话题 默认日期倒叙
     * 3、圈子置顶话题 某个圈子置顶 sort
     * 4、我发表的话题
     * 5、我评论的话题
     * 6、我点赞的话题
     * 7、我收藏的话题
     * 8、首页话题 按照标题感想  搜索
     * 9、我的足迹 浏览足迹 添加
     * 10、我关注人的话题
     */


    /**
     * 首页页面话题 查询 
     * @param QueryEntity
     * @return
     */
    @PostMapping("queryIndexTopic")
    @LoggerOperation(module = "圈子首页话题", message = "查看", type = LoggerEnumerate.SELECT)
    @PreAuthorize("hasAuthority('circle:topic:queryIndexTopic')")
    public List<QueryEntity> queryIndexTopic(@RequestBody CircleTopic QueryEntity){
        return  circleTopicService.queryIndexTopic(QueryEntity);
    }




    /**
     * 圈子话题 添加
     * @param images 图片集
     * @param topic 实体类
     */
    @PostMapping
    @LoggerOperation(module = "圈子话题", message = "添加", type = LoggerEnumerate.INSERT)
    public void save(@RequestPart MultipartFile[] images,@RequestPart CircleTopic topic) throws IOException {

        circleTopicService.insert(images, topic);
    }

    /**
     * 圈子话题 修改
     * @param entity 实体类
     */
    @PutMapping
    @LoggerOperation(module = "圈子话题", message = "修改", type = LoggerEnumerate.UPDATE)
    public void update(@Valid @RequestBody CircleTopic entity) {
        circleTopicService.updateById(entity);
    }

    /**
     * 圈子话题 单删
     * @param id 主键id
     */
    @DeleteMapping("{id}")
    @LoggerOperation(module = "圈子话题", message = "单删", type = LoggerEnumerate.DELETE)
    public void delete(@NotNull(message = "主键ID不能为null") @PathVariable int id) {
        circleTopicService.removeById(id);
    }

    /**
     * 圈子话题 批删
     * @param ids 主键id集合
     */
    @DeleteMapping
    @LoggerOperation(module = "圈子话题", message = "批删", type = LoggerEnumerate.DELETE)
    public void delete(@RequestBody @NotEmpty(message = "主键ID不能为null") Collection<Integer> ids) {
        circleTopicService.removeByIds(ids);
    }

    /**
     * 圈子话题 主键ID查询
     * @param id 主键id
     * @return 实体类
     */
    @GetMapping("{id}")
    @LoggerOperation(module = "圈子话题", message = "主键查询", type = LoggerEnumerate.SELECT)
    public CircleTopic load(@PathVariable @NotNull(message = "主键ID不能为null") int id) {
        return circleTopicService.getById(id);
    }

    /**
     * 圈子话题 分页查询
     * @param entity 主键对象
     * @return 分页对象
     */
    @PostMapping("page")
    @LoggerOperation(module = "圈子话题", message = "分页查询", type = LoggerEnumerate.SELECT)
    public Page<CircleTopic> page(@RequestBody CircleTopic entity) {
        return circleTopicService.page(entity);
    }

}